$file1 = $ARGV[0];
chomp($file1);
$file2 = $ARGV[1];
chomp($file2);
open(BUFF1,$file1) or die "no file exists\n";
open(BUFF2,$file2) or die "no file $file2 exists\n";
while(<BUFF1>)
{
	chomp($_);
	@array = split(' ',$_);
	$hash{$array[0]} = 1;
	#print "$array[0]\n";
}
$n = 0;
while(<BUFF2>)
{
        chomp($_);
        @array = split(' ',$_);
        if(exists($hash{$array[0]}) && (!exists($hash1{$array[0]}))) 
	#if(exists($hash{$array[0]}))
	{
		$hash1{$array[0]} = $n;
		$n++;
	#	print "$n\n";
	}
}
open(BUFF1,$file1);
open(BUFF2,$file2);
open(WRBUFF1,">out_$file1");
open(WRBUFF2,">out_$file2");
@array = ();
@arr = ();
while(<BUFF1>)
{
        chomp($_);
        @array = split(' ',$_);
	$arr[$hash1{$array[0]}] =$_;
}
for($i=0;$i<@arr;$i++)
{
	print WRBUFF1 $arr[$i]."\n";
}
@arr = ();
while(<BUFF2>)
{
        chomp($_);
        @array = split(' ',$_);
        $arr[$hash1{$array[0]}] =$_;
}
for($i=0;$i<@arr;$i++)
{
        print WRBUFF2 $arr[$i]."\n";
}

